class AVRiL extends SRKFWeaponShotgun;

#exec OBJ LOAD FILE=SCTextures.utx

var transient float LastFOV;
var() bool zoomed;
var color ChargeColor;
var float ZoomLevel;
var float Range;
var float LastRangingTime;
var float LastRangeFound;
var() Material ZoomMat;
var() Sound ZoomSound;

simulated event WeaponTick(float dt)
{
	if(AmmoAmount(0) == 0)
		MagAmmoRemaining = 0;
	super.Weapontick(dt);
}

replication
{
	reliable if(Role < ROLE_Authority)
		ServerChangeFireMode;
}


// Use alt fire to switch fire modes
simulated function AltFire(float F)
{
    if(ReadyToFire(0))
    {
        DoToggle();
    }
}

// Set the new fire mode on the server
function ServerChangeFireMode(bool bNewWaitForRelease)
{
    FireMode[0].bWaitForRelease = bNewWaitForRelease;
}


function bool RecommendRangedAttack()
{
	return true;
}

function bool RecommendLongRangedAttack()
{
	return true;
}

function float SuggestAttackStyle()
{
	return -1.0;
}

exec function SwitchModes()
{
  DoToggle();
}


simulated event RenderOverlays(Canvas Canvas)
{
	local PlayerController PC;

	PC = PlayerController(Instigator.Controller);

	if(PC == None)
		return;


/*	  if ( !PC.bFrozen )
		{
			SetZoomBlendColor(Canvas);
			Canvas.Style = ERenderStyle.STY_Normal;
			Canvas.Style = 255;
			Canvas.SetPos((Canvas.SizeX - Canvas.SizeY) / 2,0);
			Canvas.DrawTile( Texture'KillingfloorHUD.ClassMenu.L85', Canvas.SizeY, Canvas.SizeY, -700, -750, 512, 512);

			Super.RenderOverlays (Canvas);
		}*/


	if(LastFOV != PC.DesiredFOV)
		PlaySound(ZoomSound, SLOT_Misc, 0.1,,,, false);

	LastFOV = PC.DesiredFOV;

	if (PC.DesiredFOV == PC.DefaultFOV || (Level.bClassicView && PC.DesiredFOV == 90))
	{
		Super.RenderOverlays(Canvas);
		zoomed=false;
	}
	else
	{
		SetZoomBlendColor(Canvas);

		
		//The view through the scope itself.
		Canvas.Style = 255;
		Canvas.SetPos((Canvas.SizeX - Canvas.SizeY) / 2,0);
		Canvas.DrawTile(ZoomMat, Canvas.SizeY, Canvas.SizeY, 0.0, 0.0, 512, 512);

		//Draw some useful text.
		Canvas.Font = Canvas.MedFont;
		Canvas.SetDrawColor(200,150,0);

		Canvas.SetPos(Canvas.SizeX * 0.33, Canvas.SizeY * 0.44);
		Canvas.DrawText("Zoom: 1.50");

		Canvas.SetPos(Canvas.SizeX * 0.33, Canvas.SizeY * 0.44);

		// Item Pickup Overlay

                // I didn't write this code, but let's leave it in as a testament to inefficiency and retardation.		

	   	Canvas.SetPos(Canvas.SizeX * 0.39, Canvas.SizeY * 0.48);
		Canvas.DrawText(Instigator.Location.Z/44 $ "", false);
	   	Canvas.SetPos(Canvas.SizeX * 0.33, Canvas.SizeY * 0.48);
		Canvas.DrawText("Elevation:");
	   	Canvas.SetPos(Canvas.SizeX * 0.33, Canvas.SizeY * 0.52);
		Canvas.DrawText("Direction:"@normalize(Instigator.GetViewRotation()).Pitch / 182.0);

        	Canvas.SetPos(Canvas.SizeX * 0.33, Canvas.SizeY * 0.56);
		if ( FireMode[0].bWaitForRelease == True )
		Canvas.DrawText("FireMode: Semi Auto");
		else
		Canvas.DrawText("FireMode: Full Auto");

		zoomed = true;
	}
}


function float GetAIRating()
{
	local Bot B;


	B = Bot(Instigator.Controller);
	if ( (B == None) || (B.Enemy == None) )
		return AIRating;

	return (AIRating + 0.0003 * FMin(VSize(B.Enemy.Location - Instigator.Location),1000));
}

function byte BestMode()
{
	return 0;
}


simulated function BringUp(optional Weapon PrevWeapon)
{
	if ( PlayerController(Instigator.Controller) != None )
	{
		LastFOV = PlayerController(Instigator.Controller).DesiredFOV;
	}
	Super.BringUp(PrevWeapon);
}

simulated function bool PutDown()
{
	if( Instigator.Controller.IsA( 'PlayerController' ) )
		PlayerController(Instigator.Controller).EndZoom();
	if ( Super.PutDown() )
	{
		GotoState('');
		return true;
	}
	return false;
}

simulated function SetZoomBlendColor(Canvas c)
{
	local Byte    val;
	local Color   clr;
	local Color   fog;

	clr.R = 255;
	clr.G = 255;
	clr.B = 255;
	clr.A = 255;

	if( Instigator.Region.Zone.bDistanceFog )
	{
		fog = Instigator.Region.Zone.DistanceFogColor;
		val = 0;
		val = Max( val, fog.R);
		val = Max( val, fog.G);
		val = Max( val, fog.B);

		if( val > 128 )
		{
			val -= 128;
			clr.R -= val;
			clr.G -= val;
			clr.B -= val;
		}
	}
	c.DrawColor = clr;
}

defaultproperties
{
     ZoomMat=Shader'KF_Weapons_Trip_T.Supers.Law_Dot_only_shdr'
     MagCapacity=1
     ReloadRate=3.000000
     ReloadAnim="Reload"
     ReloadAnimRate=3.000000
     WeaponReloadAnim="Reload_LAW"
     MinimumFireRange=300
     HudImage=Texture'SCTextures.AVRiL'
     SelectedHudImage=Texture'SCTextures.AVRiL'
     Weight=14.000000
     bHasAimingMode=True
     IdleAimAnim="Reload"
     StandardDisplayFOV=75.000000
     SleeveNum=3
     TraderInfoTexture=Texture'SCTextures.AVRiL'
     PlayerIronSightFOV=70.000000
     ZoomTime=0.260000
     ZoomedDisplayFOV=179.000000
     FireModeClass(0)=Class'PerksSimHostOrg.AVRiLFire'
     FireModeClass(1)=Class'PerksSimHostOrg.AVRiLAltFire'
     PutDownAnim="PutDown"
     SelectSound=Sound'KF_LAWSnd.LAW_Select'
     SelectForce="SwitchToRocketLauncher"
     AIRating=1.500000
     CurrentRating=1.500000
     bSniping=False
     Description="The rocket, powerful alt fire!"
     EffectOffset=(X=50.000000,Y=1.000000,Z=10.000000)
     DisplayFOV=75.000000
     Priority=210
     HudColor=(G=0)
     InventoryGroup=4
     GroupOffset=4
     PickupClass=Class'PerksSimHostOrg.AVRiLPickup'
     PlayerViewOffset=(X=40.000000,Y=40.000000,Z=-10.000000)
     PlayerViewPivot=(Pitch=30)
     BobDamping=7.000000
     AttachmentClass=Class'PerksSimHostOrg.AVRiLAttachment'
     IconCoords=(X1=429,Y1=212,X2=508,Y2=251)
     ItemName="AVRiL"
     Mesh=SkeletalMesh'AVRiL-A.AVRiL_1st'
     DrawScale=0.500000
     Skins(0)=Combiner'KillingFloorWeapons.Welder.CombinerWeldWindow'
     Skins(1)=Texture'KF_Weapons2_Trip_T.Special.AA12_D'
     AmbientGlow=2
}
